﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ReAnimation.MVP.Models.Interfaces;
using Sharp3D.Math.Core;
using ReAnimation.MVP.ViewInterfaces;

namespace ReAnimation.MVP.Views
{
    public partial class MoleculeTransformMatrixView : BaseUserControlView, IMoleculeTransformMatrixView
    {
        private IMainModel _mainModel;

        public MoleculeTransformMatrixView(IMainModel mainModel)
        {
            _mainModel = mainModel;

            InitializeComponent();

            _mainModel.CurrentMoleculeChanged += (s, o) => { UpdateZMatrixViewFromMolecule(); };
            _mainModel.CurrentMoleculeStructureChanged += (s, o) => { UpdateZMatrixViewFromMolecule(); };
            _mainModel.CurrentMoleculeTransformMatrixChanged += (s, o) => { UpdateZMatrixViewFromMolecule(); };
        }

        private void UpdateZMatrixViewFromMolecule()
        {
            IList<object> matrix = new List<object>()
            {
                new {v0 = 1, v1 = 0, v2 = 0, v3 =0},
                new {v0 = 0, v1 = 1, v2 = 0, v3 =0},
                new {v0 = 0, v1 = 0, v2 = 1, v3 =0},
                new {v0 = 0, v1 = 0, v2 = 0, v3 =1},
            };

            if (_mainModel.CurrentMolecule != null)
            {
                Matrix4F m = _mainModel.CurrentMolecule.TransformMatrix;
                matrix = new List<object>()
                {
                new{ v0 = m.M11, v1 = m.M12, v2 = m.M13, v3 = m.M14},
                new{ v0 = m.M21, v1 = m.M22, v2 = m.M23, v3 = m.M24},
                new{ v0 = m.M31, v1 = m.M32, v2 = m.M33, v3 = m.M34},
                new{ v0 = m.M41, v1 = m.M42, v2 = m.M43, v3 = m.M44}
                };
            }

            transformMatrixBindingSource.DataSource = matrix;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
